<?php


namespace app\api\model;

use think\Db;
use think\Model;

class Banner extends BaseModel {


    //隐藏字段，即查询自己想要的字段
    protected $hidden=array('delete_time','update_time');

    public function items(){
        return $this->hasMany('BannerItem','banner_id','id');
    }


    public static function getBanner($id){
        $list = self::with(array('items','items.img'))->find($id);
        return $list;
    }


//      public static function getBanner($id){
//         $banner =  Db::table('banner')->where('id',$id)->field(['id','name','description'])->find();
//         //获取benner_item
//          $banner['item'] = Db::table('banner_item')->where('banner_id',$banner['id'])->field(['id','img_id','key_word','type'])->select()->toArray();
//          foreach ($banner['item'] as &$value){
//              $value['img']=Db::table('image')->where('id',$value['img_id'])->field(['id','url','from'])->find();
//              $value['img']['url'] = imgUrl($value['img']['url'],$value['img']);
//          }
//          return $banner;
//      }




}






















































































































